from . import ConnectMysql 

class Detail(ConnectMysql):

    def detail(self,ID):

        detail_sql = 'select * from company where id = %s'

        self.cursor.execute(detail_sql,(ID,))

        result = self.cursor.fetchone()

        return result

    def openid_verify(self,openid,ID):

        result_info = self.detail(ID)

        if not result_info:

            return{
                'status':-1,
                'errorCode':604,
                'errorMsg':'没有找到此ID',
                'resultBody':None 
            }
        
        openid_sql = 'select * from openid where openid=%s and pay=1'

        self.cursor.execute(openid_sql,(openid,))

        result = self.cursor.fetchone()

        if result:

            return{
                'status':1,
                'errorCode':None,
                'errorMsg':None,
                'resultBody':result_info }

        else:
            result_info['phone'] = result_info['phone'][0:3] +'****'+result_info['phone'][-4:]
            return{
               'status': 1,
                'errorCode':None,
                'errorMsg':None,
                'resultBody':result_info
            }
            